package com.etogc.groupchat.group.ui;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.etogc.groupchat.R;
import com.etogc.groupchat.base.BaseActivity;
import com.etogc.groupchat.group.adpt.MemberAdapter;
import com.etogc.groupchat.group.biz.GroupHttpBiz2;
import com.etogc.http.ReqDataHandler;
import com.etogc.http.ReqErrorHandler;
import com.etogc.http.VolleyHttpUtil;
import com.etogc.util.IntentHelper;
import com.etogc.util.YcToastHelper;
import com.etogc.view.LoadDialog;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 成员管理
 */
public class MgrMemberActivity extends BaseActivity {
    //BaseRecyleViewActivity
//    ic_private SwipeRefreshLayout mSwipeRefreshLayout;
//    ic_private YfListRecyclerView recyclerView;
    private RecyclerView recyclerView;
    private MemberAdapter adapter;
    private String groupID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mgr_member);
        ((TextView) findViewById(R.id.tvTitle)).setText("" + "群成员");
        adapter = new MemberAdapter(this);
        groupID = getIntent().getStringExtra("groupID");
        recyclerView = findViewById(R.id.recyclerView);
        findViewById(R.id.ivBack).setVisibility(View.VISIBLE);
        findViewById(R.id.ivBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentHelper.finish(MgrMemberActivity.this);
            }
        });
        initView();
        requestMemberList();
    }

    private void initView() {
        recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        recyclerView.setAdapter(adapter);
//        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
//        });
    }

    private void requestMemberList() {
        GroupHttpBiz2.getMemberList(this, groupID, new VolleyHttpUtil.ResponseCallBack() {
            @Override
            public void handleResponse(JSONObject response, int errCode) {
                LoadDialog.dismiss(MgrMemberActivity.this);
                boolean isSuccess = ReqErrorHandler.getInstance().isSuccess(response, true);
                if (isSuccess) {
                    Map<String, Object> map = ReqDataHandler.getMapWithEntityNoGson(response);
                    List<HashMap<String, String>> list = (List<HashMap<String, String>>) map.get("list");
                    if (list != null && list.size() > 0) {
                        adapter.setData(list);
                    } else {
                        YcToastHelper.getInstance()._toast("暂无数据");
                    }
                }
            }
        });
    }

//    @Override
//    protected SwipeRefreshLayout getSwipeRefreshLayout() {
//        mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
//        return mSwipeRefreshLayout;
//    }
//
//    @Override
//    protected void refresh() {
//
//    }
//
//    @Override
//    protected void loadMoreData() {
//
//    }
//
//    @Override
//    protected RecycleViewAdapter getAdapter() {
//        return null;
//    }


}
